<?php
/*
 * [佳喜网络!] (C)2008-2009 JiaXi Inc.
 * $Id: user.php 2008-8-13 19:28:02z pepsi.zh $
 * 后台用户管理员操作类
 * -------------------------------------------
 * 网址：www.he88.cn
 * -------------------------------------------
 * 这是一个共享软件，遵循我们公司的共享协议。
*/

if (!defined('IN_SITE')){ die('Hacking attempt!'); } 
interface UserInterface{
	### 功能：用户登陆判断  参数：$username 用户名；$password 用户密码 #####
    function userLogin($username,$password);
    ### 功能：测试用户名是否存在 $username 用户名
    function checkExists($username);
    ### 功能：返回用户信息
    function getUserInfo($userid);
}
class user implements UserInterface {
	function userLogin($username,$password){
		global $dbtable,$dbconn;
		$username = trim($username);
		if (empty($username)){
			return false;
		}else {
			$password = md5($password);
		}
		$query = "select a.zuserid,a.zusername,b.ztypename,b.zsitenum,b.zwebnum from $dbtable->user a left join $dbtable->userT b on(a.ztypeid=b.ztypeid) where a.zusername='$username' and a.zpassword='$password' limit 1";
		$record = $dbconn->Getonerecord($query);
		if ($record){
			$_SESSION[userType] = $record[ztypename];
			$_SESSION[userId] = $record[zuserid];
			$_SESSION[userName] = $record[zusername];
			$_SESSION[siteNum] = $record[zsitenum];
			$_SESSION[webNum] = $record[zwebnum];
			$dbconn->updateData(array('zlogindate'=>time(),'zloginip'=>get_ip(),'zlogintimes'=>'zlogintimes+1'),$dbtable->user,array('zuserid'=>$record[zuserid]));
			return true;
		}else {
			return false;
		}
	}
	function checkExists($username){
		global $dbtable,$dbconn;
		if (empty($username)){
			return false;
		}
		$query = "select count(*) from $dbtable->user where zusername='$username'";
		return $dbconn->Getonefield($query);
	}
	function getUserInfo($userid){
		global $dbtable,$dbconn;
		if (empty($userid)){
			return false;
		}
		$query = "select a.*,b.ztypename,b.zsitenum,b.zwebnum from $dbtable->user a left join $dbtable->userT b on(a.ztypeid=b.ztypeid) where a.zuserid=$userid limit 1";
		$array = $dbconn->Getonerecord($query);
		$array[zregdate] = date('Y-m-d H:i:s',$array[zregdate]);
		$query = "select count(*) from $dbtable->site where zuserid=$userid";
		$array[zsiteall] = $dbconn->Getonefield($query);
		$query = "select count(*) from $dbtable->web a left join $dbtable->site b on(a.zsite=b.zsiteid) where b.zuserid=$userid";
		$array[zweball] = $dbconn->Getonefield($query);
		return $array;
	}
}

?>